package library.gui.scene;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.layout.VBox;

import library.gui.SystemApplication;
import library.gui.component.FunctionalButton;
import library.gui.component.HButtonList;
import library.gui.component.InputList;
import library.gui.component.TitleLabel;
import library.gui.dialog.NotiDialog;
import library.utils.Info;

public class RegisterPane extends VBox{
	
	SystemApplication handler;
	
	private int width = 320;
	
	private TitleLabel titleLabel = new TitleLabel("注册");
	private InputList inputList = new InputList();
	private HButtonList buttonList;
	
	public RegisterPane(SystemApplication handler) {

		this.handler = handler;
//		buttonList.setPrefWidth(width);
		this.setPrefWidth(width);
		this.setAlignment(Pos.CENTER);
//		titleLabel.prefWidthProperty().bind(this.widthProperty());
		inputList.addKey("用户名").addSecretedKey("密码")
			.addSecretedKey("确认密码").addKey("邮箱")
			.addChoiceKey("学院", SystemApplication.DEPARTMENT);
		inputList.setPadding(new Insets(10));
		inputList.prefWidthProperty().bind(this.widthProperty());
		
		buttonList = new HButtonList(
			new FunctionalButton("注册", ()->{
				Info info = handler.getLibrary().register(
					inputList.get("用户名"), inputList.get("密码"), 
					inputList.get("确认密码"), inputList.get("邮箱"), inputList.get("学院"));
				if(info.isSuccess()) {
					new NotiDialog("注册成功", info.toString()).showAndWait();
					handler.toMainMenuScene();
				}
				else {
					new NotiDialog("注册失败", info.toString()).showAndWait();
				}
			}),
			new FunctionalButton("返回", handler::toMainMenuScene)
		);
		buttonList.prefWidthProperty().bind(this.widthProperty());

		this.getChildren().add(titleLabel);	
		this.getChildren().add(inputList);	
		this.getChildren().add(buttonList);
		
//		this.setTop(titleLabel);
//		this.setCenter(inputList);
//		this.setBottom(buttonList);
		
	}
	
}
